// eslint-disable-next-line import/named
import { GetterTree } from 'vuex'
import { StateInterface } from './state'

const getters: GetterTree<StateInterface, StateInterface> = {
  isLogin (state) {
    const role = state.userInfo.role
    return role !== 99
  },
  isShare (state) {
    return !!state.shareId
  },
  storageKey (state) {
    const userId = state.userInfo._id
    const userKey = state.currentWorkbenchId ? userId : `${userId}_${state.currentWorkbenchId}`
    return `WORKBENCH_DATA_${userId ? userKey : 'TEMP'}`
  },
  storageQuery (state) {
    return state.currentWorkbenchId === 'main'
      ? { type: 1 }
      : {
        type: 2,
        tag: state.currentWorkbenchId
      }
  }
}

export default getters
